package cn.fxl.xhr;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * 消息发送
 */
public class SyncProducer {
    public static void main(String[] args) throws Exception {
        // 实例化消息生产者Producer
        DefaultMQProducer producer= new DefaultMQProducer("please_rename_unique_group_xhr");
        producer.setNamesrvAddr("localhost:9876");
        producer.start();
        Message message = new Message("TopicXhrTest", "TagB", "嘿嘿嘿".getBytes(RemotingHelper.DEFAULT_CHARSET));
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println(sendResult);
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("发送错误"+throwable.getMessage());
            }
        });
        System.out.println("异步");
       // producer.shutdown();
    }
}
